// 搜索页面api
import _ajax from './request.js'
// 获取文章详情信息
function articleDetail (id) {
  return _ajax({
    url: '/v1_0/articles/' + id
  })
}
// 对文章点赞
function apiZan (artid) {
  return _ajax({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: artid
    },
    needToken: true
  })
}

// 取消文章的点赞
function apiDiszan (artid) {
  return _ajax({
    url: `/v1_0/article/likings/${artid}`, // 这个路径中需要传入一个参数键为：target
    method: 'DELETE',
    needToken: true
  })
}
// 封装方法：联想建议
function suggestion (params) {
  return _ajax({
    url: 'v1_0/suggestion',
    params
  })
}
// 获取搜索结果
function search (params) {
  return _ajax({
    url: 'v1_0/search',
    params
  })
}

// 关注用户
function apiFollow (autid) {
  return _ajax({
    url: '/v1_0/user/followings',
    method: 'POST',
    needToken: true,
    data: {
      target: autid
    }
  })
}
// 取关用户
function apiUnFollow (autid) {
  return _ajax({
    url: `/v1_0/user/followings/${autid}`,
    method: 'DELETE',
    needToken: true
  })
}
// 对文章不喜欢
function apiDislike (artid) {
  return _ajax({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    needToken: true,
    data: {
      target: artid
    }
  })
}
export {
  articleDetail,
  apiZan,
  apiDiszan,
  apiFollow,
  apiUnFollow,
  apiDislike,
  suggestion,
  search
}
